var ibmdb = require('ibm_db')
// var connStr = "DATABASE=sample;HOSTNAME=10.10.3.12;UID=db2inst1;PWD=12345678;PORT=50000;PROTOCOL=TCPIP";
var connStr =
  'DATABASE=demo1;HOSTNAME=10.10.3.12;UID=db2inst1;PWD=12345678;PORT=50000;PROTOCOL=TCPIP;CHARSET=utf8'

// ibmdb.open(connStr, function (err,conn) {
//   if (err) return console.log(err);

//   conn.query("SELECT TOPNAME FROM test1.ITSM_UNIONQUERYVIEW WHERE CODE='20230228019'", function (err, data) {
//     if (err) console.log(err);
//     else console.log(data);

//     conn.close(function () {
//       console.log('done');
//     });
//   });
// });
;(async function () {
  try {
    process.env.DB2CODEPAGE = 1208
    let conn = await ibmdb.open(connStr)
    // await conn.query('db2set db2codepage=1208')
    await conn.query(
      'insert into test1.ITSM_UNIONQUERYVIEW (QUERYCOUNT,CODE,ID,TOPNAME) VALUES (?, ?, ?, ?)',
      // [100, '888', '111', 'D金刚与王尼玛']
      [100, '888', '111', '金刚与王尼玛3']
      // "insert into test1.ITSM_UNIONQUERYVIEW (QUERYCOUNT,CODE,ID,TOPNAME) VALUES (100, '777', '111', '大金刚与王尼玛')"
      // [100, '777', '111', '大金刚与王尼玛']
    )
    let stmt = await conn.prepare('select * from test1.ITSM_UNIONQUERYVIEW')
    let result = await stmt.execute()
    data = await result.fetchAll()
    console.log('result = ', data)
    await result.close()
    await stmt.close()
    await conn.close()
  } catch (e) {
    console.log(e)
  }
})()
